
const t = new Date()
const _m = (t.getMonth()+1).toString()
const _d = t.getDate().toString()


// 当前年
const yyyy  = t.getFullYear().toString()
// 当前月
const m = _m
// 当前月补零
const mm = _m<10?'0'+_m:_m
// 当前日
const d = _d
// 当前日补零
const dd = _d<10?'0'+_d:_d


function get_Next_Pre_Year(np,t){
  let year = parseInt(t)
  if(t === yyyy){
    return t
  }
  if(np === 'n'){
    return year+1
  }else{
    return year-1    
  }
}
function get_Next_Pre_Month(np,t){
  let y = parseInt(t.split('-')[0])
  let m = parseInt(t.split('-')[1])
  if(np === 'n'){
    if(t === yyyy+'-'+mm){
      return t
    }
    if(m === 12){
      return y+1+'-'+'01'
    }else{
      return y+'-'+((m+1)<10?'0'+(m+1):(m+1))
    }
  }else{
    if(m === 1){
      return y-1+'-'+'12'
    }else{
      return y+'-'+((m-1)<10?'0'+(m-1):(m-1))
    }
  }
}

function get_Next_Pre_Date(np,t){
  let y = parseInt(t.split('-')[0])
  let m = parseInt(t.split('-')[1])
  let d = parseInt(t.split('-')[2])
  let now_d = new Date(y,m,0).getDate()
  if(np === 'n'){
    if(t === yyyy+'-'+mm+'-'+dd){
      return t
    }
    if(d === now_d && m === 12){
      return y+1+'-01-01'
    }
    else if(d === now_d && m !== 12){
      return y+'-'+((m+1)<10?'0'+(m+1):(m+1))+'-01'
    }
    else{
      return y+'-'+(m<10?'0'+m:m)+'-'+((d+1)<10?'0'+(d+1):(d+1))      
    }
  }else{
    if(d === 1 && m === 1){
      return y-1+'-12-'+new Date(y-1,12,0).getDate()
    }
    else if(d === 1 && m !== 1){
      return y+'-'+((m-1)<10?'0'+(m-1):(m-1))+'-'+new Date(y,m-1,0).getDate()
    }
    else{
      return y+'-'+(m<10?'0'+m:m)+'-'+((d-1)<10?'0'+(d-1):(d-1))      
    }
  }
}
const date = {
  'ymd':yyyy+'-'+mm+'-'+dd,
  'ym':yyyy+'-'+mm,
  'md':mm+'-'+dd,
  yyyy,
  m,
  mm,
  d,
  dd,
  get_Y:get_Next_Pre_Year,
  get_M:get_Next_Pre_Month,
  get_D:get_Next_Pre_Date
}
export default date